/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 九转苍翎
 * Date: 2025/9/2
 * Time: 21:07
 */
public class Solution {
    public int singleNumber(int[] nums) {
        int ret = 0;
        for (int i = 0; i < 32; i++) {//遍历每一个比特位
            int sum = 0;
            for (int cur : nums) {//统计nums中所有的数第i位的和
                if (((cur >> i) & 1) == 1) {
                    sum++;
                }
            }
            sum %= 3;
            if (sum == 1) {
                ret = ret | (1 << i);
            }
        }
        return ret;
    }
    public static void main(String[] args) {
        Solution solution = new Solution();
        int ret = solution.singleNumber(new int[]{1, 1, 3, 1});
        System.out.println(ret);
    }
}